import sys
from pathlib import Path
import pandas as pd  # 新增导入

# 确保项目根目录在Python路径中
PROJECT_ROOT = Path(__file__).parent.parent
sys.path.insert(0, str(PROJECT_ROOT))

# 添加项目初始化代码
if __name__ == "__main__":
    from src.data_preprocessing.dataset_builder import build_dataset
    from src.data_preprocessing.font_parser import parse_fonts
    from src.configs import base_config

    # 修改parse_fonts调用
    parse_fonts(
        raw_ttf_dir=base_config['data']['raw_ttf_dir'],
        output_svg_dir=base_config['data']['processed']['svg_dir'],
        metadata_path=os.path.join(base_config['data']['processed']['svg_dir'], "metadata.csv")
    )
    
    # 修改数据集构建
    metadata = pd.read_csv(os.path.join(base_config['data']['processed']['svg_dir'], "metadata.csv"))
    print(f"发现{len(metadata)}个SVG文件，开始处理...")
    
    success_count = build_dataset(metadata)
    print(f"成功处理{success_count}/{len(metadata)}个文件")